//window.localStorage.isWeiXin
import base64_encode from "../../utils/base64_encode";
import car_number_keyboard_popup from "../car-manage/components/car-number-keyboard-popup.vue"
import {
  Toast
} from 'vant';
import countryCode from "@/components/countryCode.vue"
export default {
  //name: 'login',
  data() {
    return {
      isInternational: window.isInternational || false,//多语言国际版是否开启，true为开启
      supplier_alone_id: null,
      login_page_mode: 1,
      country_code: 0,//区号开关
      isWalletLogin:false,//钱包app登录开关
      wetach_login: false, //APP微信登陆是否开启
      appShow: false, //APP手机号登陆是否开启
      authCodeStatus: true, //验证码是否可以点击
      imgcode: "", //验证码图片地址
      passwordShow: false,
      form: {
        country: "86",
        mobile: "",
        password: "",
        code: "",
        captcha: "",
        uuid: "",
        mid: 0,
        mobileErr: "",
        passwordErr: "",
        login_checked: false, //协议是否选中
      },
      btnText: this.$i18n.t('base.getSmsCode'),
      timer: null,
      loading: false,
      start1: false,
      ys_short_url_redirect_url: '',
      ys_short_url_redirect_tel: '',
      mobile_login_code: 0,
      password_login_code: '',
      login_type: 1,
      wechat_qrcode_config: { //微信扫码登录配置
        callback: "",
        is_open: "",
        is_wechat_login: "",
        wechat_login_type: ""
      },
      is_enable: '',
      enable_btn: '',
      need_family: true,
      account_url: '',
      pc_bind_mobile: "",
      mobileForm: {
        code: "",
        captcha: "",
        mobile: ""
      },
      btnTag: false,
      showChangeID: false,
      changidInfo: {},
      loginStatus: false, //登录图标切换
      title: {
        mainHeading: '', //主标题
        subheading: '', //副标题
        mailInfo_logo: '', //商城图标
      },
      registryEntry: '', //是否显示注册入口
      loginToSwitch: { //是否显示登录方式切换
        mobile_login_code: '',
        is_enable: '',
      },
      platformAgreement: '', //平台协议
      registrationProtocol: '', //注册协议
      popUpShow: false, //飘窗是否弹出
      accountAndPasswordLogin: false, //是否为账号密码登录
      phoneAndPassword: false, //是否为手机号密码
      nameOfTheMall: '', //商城名称
      openPlatformAgreement: false,
      popoverProtocolContent: '', //弹窗协议内容
      loginModeSwitchButton: '', //登陆切换按钮
      isShowBottom: true, //键盘弹出隐藏
      clientHeight: document.documentElement.clientHeight, //默认屏幕高度
      apptoken: "",
      appPlatform:false,//是否为App端
      // 余额
      balance:'余额',
      // 积分
      point:'积分',
      is_year_end_box_login:false,
      email_login:0,
      car_manage_is_register_bind:false,
      openPopUp:false,
      images_n: require("../../assets/images/logindefault_bg@2x.png"),
      login_banner_url:""
    };
  },
  created() {
    try {
      let supplier_alone_id = this.fun.getKey('supplier_alone_id') || sessionStorage.getItem("supplier_alone_id") || null; //供应商独立模板，获取供应商id
      this.supplier_alone_id = supplier_alone_id||false;
    } catch (error) {
      console.log(error);
    }
  },
  computed:{
    setBackground(){
      if(this.login_page_mode == 0){
        // 主题色+文字
        return {'background-color': `var(--themeBaseColor)`}
      } else {
        // 图片+文字
        return {backgroundImage: `url(${this.login_banner_url?this.login_banner_url:this.images_n})`}
      }
    }
  },
  mounted() {
    this.newLoginInformation()
    this.realTimePageHeight()
    this.start1 = false;
    this.ys_short_url_redirect_url = this.fun.getCookie('ys_short_url_redirect_url');
    this.ys_short_url_redirect_tel = this.fun.getCookie('ys_short_url_redirect_tel');
    if (this.ys_short_url_redirect_tel) {
      this.form.mobile = this.ys_short_url_redirect_tel;
      this.mobile_login_code = 1;
      this.getimgdata();
      this.loading = true;
    } else {
      this.getLoginMode();
    }
    let app = this.fun.getTyep();
    if (app == "7") {
      this.appPlatform = true
      this.isAppLogin();
    } else {
      this.appPlatform = false
      this.appShow = true;
    }
    this.apptoken = this.$route.query.apptoken;
    this.init_login();
    this.init_appCoinK();//第三方app授权登录开发【#902】
  },
  watch: {
    form: { //监听form对象改变情况
      handler(newVal, oldVal) {
        this.loginButtonStatus()
      },
      deep: true, // 深度监听
      immediate: true, // 初始化监听
    },
    'form.login_checked': { //监听协议是否勾选popUpShow
      handler(newVal, oldVal) {
        this.popUpShow = !this.form.login_checked
      },
    }
  },
  methods: {
    loginButtonStatus() { //登录按钮状态
      let agreement = this.registrationProtocol.status == 1 || this.platformAgreement.status == 1
      if (this.phoneAndPassword) { //手机号密码登陆
        if (agreement || this.appPlatform) {
          if (!this.fun.isTextEmpty(this.form.password) && !this.fun.isTextEmpty(this.form.mobile) && this.form
            .login_checked) {
            this.loginStatus = true
          } else {
            this.loginStatus = false
          }
        } else {
          if (!this.fun.isTextEmpty(this.form.password) && !this.fun.isTextEmpty(this.form.mobile)) {
            this.loginStatus = true
          } else {
            this.loginStatus = false
          }
        }
      } else if (this.mobile_login_code == 1 && this.is_enable == 0) { //手机验证码登陆
        if (agreement) {
          if (!this.fun.isTextEmpty(this.form.mobile) && !this.fun.isTextEmpty(this.form.code) && this.form
            .login_checked) {

            this.loginStatus = true
          } else {
            this.loginStatus = false
          }
        } else {
          if (!this.fun.isTextEmpty(this.form.mobile) && !this.fun.isTextEmpty(this.form.code)) {
            this.loginStatus = true
          } else {
            this.loginStatus = false
          }
        }
      } else if (this.accountAndPasswordLogin) { //账号密码登陆
        if (agreement) {
          if (!this.fun.isTextEmpty(this.form.mobile) && !this.fun.isTextEmpty(this.form.password) && this.form
            .login_checked) {
            this.loginStatus = true
          } else {
            this.loginStatus = false
          }
        } else {
          if (!this.fun.isTextEmpty(this.form.mobile) && !this.fun.isTextEmpty(this.form.password)) {
            this.loginStatus = true
          } else {
            this.loginStatus = false
          }
        }
      }
    },
    realTimePageHeight() { //获取页面实时高度
      window.onresize = () => {
        if (this.clientHeight > document.documentElement.clientHeight) {
          this.isShowBottom = false
        } else {
          this.isShowBottom = true
        }
      }
    },
    init_login() {
      if (!this.fun.isApp()) {
        return;
      }
      if (!YDB_isWXApp||this.fun.isWalletApp()) {
        return;
      }
      if (this.apptoken) {
        this.login({
          apptoken: this.apptoken
        });
      } else {
        $http
          .get("member.login.index", {
            show_wechat_login: true
          })
          .then(response => {
            if (response.result == 1) {
              this.wetach_login = parseInt(response.data.wetach_login);
            }
          });
      }
    },
    weixin() { //云打包app微信登陆
      if (this.fun.isApp() && !this.form.login_checked) {
        Toast("请先勾选登录即代表您同意《用户协议》和《隐私政策》！");
        return;
      }
      Toast.loading({
        duration: 0,
        forbidClick: true,
        message: "正在登录"
      });
      window.localStorage.setItem("isWxLogin", 0);
      let accessUrl = this.fun.getSiteRoot() + this.fun.getRealUrl("member.login.index", {uuid:YDB_UUID});
      YDB.WXLogin(0, accessUrl);
    },
    walletAppLogin(){
      window.localStorage.removeItem('uid');
      let _this = this;
      if (!this.form.login_checked) {
        Toast("请先勾选登录即代表您同意《用户协议》和《隐私政策》！");
        return;
      }
      // 钱包app登录，会员首次点击钱包登录跳转到绑定信息页面进行信息绑定邀请码：根据商城会员设置邀请码是否必填,显示手机号跳转绑定手机号页面
      jsBridge.getCurrentBTYAddress({},(v)=>{
        // alert(v);
        _this.$toast(v);
        if(v) _this.walletAppLoginApi(v);
      });
      // jsBridge.call("getCurrentBTYAddress", function (v) {
      //   alert(v);
      //   if(v) _this.walletAppLoginApi(v);
      // });
    },
    async walletAppLoginApi(wallet_site) {
      let { result, msg, data } = await $http.post("member.login.index", { wallet_site: wallet_site, mid: 0 });
      if (result == 0) return this.$toast(msg);
      window.localStorage.setItem("isWxLogin", 0);
      // 如果是首次登录（钱包注册登录的）需要跳转到邀请页
      if(data.first_login){
        return this.$router.push(this.fun.getUrl("inviterAndPhone",{},{requiredInviter: 0}));
      }
      if (data.url) {
        window.location.href = data.url;
      } else {
        this.$router.push(this.fun.getUrl("home"));
      }
    },

    openOpenPlatformAgreement(e) { //弹出用户协议弹窗
      this.openPlatformAgreement = true;
      this.agreementContent(e)
    },
    appAgreement(e) { //app协议跳转
      this.$router.push(this.fun.getUrl("userAgreement",{},{ show:e}));
    },
    agreementContent(e) { //获取协议内容
      let that = this
      let url = ''
      if (e == 'user') {
        url = 'member.member-info.register-agreement'
      } else if (e == 'platform') {
        url = 'member.member-info.platform-agreement'
      }
      $http.get(url).then(function(response) {
        if (response.result == 1) {
          that.popoverProtocolContent = response.data
        }
      }, function(response) {
        // error callback
      });
    },
    viewPasswordSwitching() { //密码显示隐藏切换
      this.passwordShow = !this.passwordShow
    },
    tapChange(e) { //登陆方式切换
      if (e == 'mobile_login_code') {
        this.mobile_login_code = 1
        this.phoneAndPassword = false
        this.accountAndPasswordLogin = false
      } else if (e == 'phoneAndPassword') {
        this.phoneAndPassword = true
        this.mobile_login_code = 0
        this.accountAndPasswordLogin = false
      } else if (e == 'accountAndPasswordLogin') {
        this.accountAndPasswordLogin = true
        this.phoneAndPassword = false
        this.mobile_login_code = 0
      } else if (e == 2) {
        this.login_type = 1
      }
      this.popUpShow = false
      this.loginButtonStatus()
    },
    async mobile_login() {
      if (this.fun.isTextEmpty(this.form.mobile)) {
        Toast(this.accountAndPasswordLogin ? "请填写账号" : this.$i18n.t('base.enterPhoneNumber'));
        return;
      }
      if (this.mobile_login_code == 1) {
        if (this.fun.isTextEmpty(this.form.code)) {
          Toast(this.$i18n.t('base.enterVerificationCode') );
          return;
        }
        if(this.is_enable == 0){
          if(this.car_manage_is_register_bind){
            let carInfoValidationResult = await this.$refs.carInfo.validation();
            console.log(carInfoValidationResult)
            this.form.car_info = {
              license_no: carInfoValidationResult.carNumber,
              license_colour: carInfoValidationResult.licensePlate,
              car_type: carInfoValidationResult.radio,
            }
          }
        }
      }

      if (this.phoneAndPassword || this.accountAndPasswordLogin) {
        if (this.fun.isTextEmpty(this.form.password)) {
          Toast("请填写密码");
          return;
        }
        delete this.form.code;
      }

      if (this.registrationProtocol.status == 1 || this.platformAgreement.status == 1 || this.appPlatform) {
        if (!this.form.login_checked) {
          // Toast("请阅读并同意协议");
          this.popUpShow = true
          return;
        } else {
          this.popUpShow = false
        }
      }

      if (this.registrationProtocol.status == 1 || this.platformAgreement.status == 1 || this.appPlatform) { //监听协议是否勾选
        if (this.form.login_checked) {
          this.popUpShow = false
        } else {
          this.popUpShow = true
        }
      }

      this.form.uuid = 0;
      let _mid = window.localStorage.getItem("mid") || this.$route.query.mid || 0;
      this.form.mid = _mid;
      this.form.is_sms = this.mobile_login_code;
      if (this.mobile_login_code != 1) {
        delete this.form.code;
      }


      let yz_redirect = sessionStorage.getItem("yz_redirect");
      const login_page_mode = this.login_page_mode;
      const login_diy_url = this.login_diy_url;
      if (login_page_mode === 1) {
        yz_redirect = base64_encode(login_diy_url);
      }
      if (yz_redirect) {
        const encodedRedirect = this.isBase64(yz_redirect) ? yz_redirect : base64_encode(yz_redirect);
        this.form.yz_redirect = encodedRedirect;
      }

      this.login(this.form);
    },
    async login(data) { //登录
      let that = this;
      let url;
      let datainfo;
      let type = "";
      let loading = "正在获取";
      // console.log(data);
      if (!this.accountAndPasswordLogin) {
        url = "member.login.index";
        datainfo = data;
      } else { //账号密码登录
        url = "plugin.account-login.frotend.member.login";
        // console.log(data);
        datainfo = {
          account: data.mobile,
          mobileErr: data.mobileErr,
          password: data.password,
          passwordErr: data.passwordErr,
          uuid: data.uuid,
          mid: data.mid,
          code: data.code,
          captcha: data.captcha
        };
      }
      if (that.wechat_qrcode_config.is_open && that.wechat_qrcode_config.wechat_login_type == 2 && that.login_type ==
        2) {
        type = "16";
        if (this.pc_token) {
          datainfo.pc_token = this.pc_token;
          loading = null;
        }
      }
      if (window.isMiniprogram) {
        // 小程序 web-view 环境
        datainfo.webview = '1';
      }
      datainfo.basic_info = 1;
      $http.post(url, datainfo, loading, "", type).then(async (response) => {
        // console.log(response);
        if (response.result === 1) {

          let isAppCoinK = this.$route.query.CoinK||false;//是否来着第三方app的跳转
          if(isAppCoinK) {
            // 第三方app登录对接，登录成功后请求接口将信息postmassge给APP
            let _Res = await $http.post("plugin.ad-task.frontend.index.login", {uid: response.msg.uid});
            if (_Res.result === 1 && _Res.data) {
              console.log('postmassge========',_Res);
              try {
                uni.postMessage({data: {sourceData: _Res.data}});
              } catch (error) {
                console.log('postmassge error========',error);
              }
            } else this.$dialog.alert({message: _Res.msg});
            return;
          }

          if (that.getIsPc() && response.data.status == 11) {
            // 扫码公众号登陆首次
            this.pc_token = response.data.pc_token;
            this.account_url = response.data.account_url;
            if (this.timer2) {
              clearInterval(this.timer2);
              this.timer2 = null;
            }
            if (!this.timer2 && this.pc_bind_mobile != 1) {
              this.timer2 = setInterval(() => {
                that.login({
                  is_pc_qrcode: 1,
                  yz_redirect: this.yz_redirect
                });
              }, 5000);
            }
          } else if (that.getIsPc() && response.data.status == 1) {
            // 扫码公众号登陆成功
            this.pc_bind_mobile = response.data.pc_bind_mobile;
            if (this.timer2) {
              clearInterval(this.timer2);
              this.timer2 = null;
            }
            sessionStorage.setItem("siteMobile", this.form.mobile);
            console.info("--会员信息--");
            console.info(response.msg);
            that.$store.commit("setLoginStatus", response.data.status);
            window.localStorage.setItem("isWxLogin", 0); // 判断是否微信授权登录
            this.login_back_url = response.data.url;

            if (this.pc_bind_mobile != 1) {
              if (this.ys_short_url_redirect_url) {
                window.location.href = that.ys_short_url_redirect_url + '&from=mobile';
                return;
              }

              if (response.data.url) {
                window.location.href = response.data.url;
              } else {
                that.$router.push(this.fun.getUrl("home"));
              }
            }
          } else {
            if (this.timer2) {
              clearInterval(this.timer2);
              this.timer2 = null;
            }

            sessionStorage.setItem("siteMobile", this.form.mobile);
            console.info("--会员信息--");
            console.info(response.msg);
            that.$store.commit("setLoginStatus", response.data.status);
            window.localStorage.setItem("isWxLogin", 0);
            if (that.fun.isApp()) {
              if (response.msg.uid) {
                YDB.SetUserRelationForPush(response.msg.uid);
              } else {
                YDB.SetUserRelationForPush(response.msg.member_id);
              }
            }
            if (this.ys_short_url_redirect_url) {
              window.location.href = that.ys_short_url_redirect_url + '&from=mobile';
              return;
            }
            if (response.data?.car_manage?.link){
              this.$dialog
                .confirm({ message: "车牌已经被绑定", confirmButtonText: "去申诉", confirmButtonColor: "#F15353" })
                .then(() => {
                  window.location.href = response.data.link;
                })
                .catch(() => {
                  that.$router.push(this.fun.getUrl("home"));
                });
              return
            }
            if (response.data.url) {
              window.location.href = response.data.url;
            } else {
              that.$router.push(this.fun.getUrl("home"));
            }
          }

        } else {
          if (response.data?.link){
            this.$dialog
              .confirm({ message: "车牌已经被绑定", confirmButtonText: "去申诉", confirmButtonColor: "#F15353" })
              .then(() => {
                window.location.href = response.data.link;
              })
              .catch(() => {
                that.$router.push(this.fun.getUrl("home"));
              });
            return
          }
          if (that.getIsPc() && response.data.status == 9) {
            let url = response.msg.url;
            if (url) {
              that.appid = that.getParam('appid', url);
              that.redirect_uri = that.getParam('redirect_uri', url);
              that.scope = that.getParam('scope', url);
              that.state = that.getParam('state', url);
            }
            this.login_obj = new WxLogin({
              // self_redirect:true,
              id: "login_code",
              appid: that.appid,
              // scope: "snsapi_login",
              scope: that.scope,
              redirect_uri: encodeURIComponent(that.redirect_uri),
              // redirect_uri:encodeURI(that.redirect_uri),
              state: that.state,
              // style: "",
              // href: ""
            });
          } else {
            if (response.data.status != 10) {
              that.$dialog.alert({
                message: response.msg
              });
            }
          }
        }
      });
    },
    getIsPc(){
      this.isQRPay = window.sessionStorage.getItem('isQRPay')||false;
      return this.fun.isPc() || this.isQRPay;
    },
    getLoginMode() {
      var that = this;
      let _json = {
        basic_info: 1
      };

      $http.get("member.login.login-mode", _json).then(response => {
        // console.log(response);
        if (response.result === 1) {
          this.loading = true;
          // PC端扫码登录
          if (that.getIsPc()) {
            that.wechat_qrcode_config = response.data.wechat_qrcode_config || {};
            if (that.wechat_qrcode_config.is_open && (that.wechat_qrcode_config.wechat_login_type == 1 || that.wechat_qrcode_config.wechat_login_type == 2)) {
              // 开启PC端微信扫码登录  1
              // 开启PC端微信扫码关注微信号登录 2
              let yz_redirect = sessionStorage.getItem("yz_redirect");
              if (!this.isBase64(yz_redirect)) yz_redirect = base64_encode(yz_redirect);
              if (this.isQRPay) {
                // 农优链大屏
                let _splitviewPage = this.fun.getSiteRoot() + "/addons/yun_shop/" + "?menu#" + "/splitview/index?i=" + this.fun.getKeyByI();
                let orderOtherParams = (window.sessionStorage.getItem("orderOtherParams") && JSON.parse(window.sessionStorage.getItem("orderOtherParams"))) || null;
                if (orderOtherParams) {
                  _splitviewPage += "&big_screen_owner_id=" + orderOtherParams.big_screen_owner_id;
                }
                yz_redirect = base64_encode(_splitviewPage);
              }
              that.login_type = 2;
              that.login({
                is_pc_qrcode: 1,
                yz_redirect: yz_redirect
              });
            }
          }
          if (response.basic_info.plugin_setting) {
            if (response.basic_info.plugin_setting.account_login) {
              // this.is_enable = response.basic_info.plugin_setting.account_login.enable;
              // this.enable_btn = response.basic_info.plugin_setting.account_login.enable;
            }
          }
        } else {
          this.loading = true;
          Toast(response.msg);
        }
      });
    },
    newLoginInformation() { //新登录接口
      $http.get("member.login.new-login-mode").then(response => {
        // console.log(response);
        if (response.result === 1) {
          let basic_info = JSON.parse(localStorage.getItem("yz_basic_info"))
          this.login_banner_url = response.data.login_banner_url;
          this.login_diy_url = response.data.login_diy_url;
          this.login_page_mode = response.data.login_page_mode;
          console.log(this.login_page_mode)
          this.balance = this.fun.getCustomTextLang('member_center.credit','余额');
          this.point = this.fun.getCustomTextLang('member_center.credit1','积分');
          this.country_code = response.data.country_code;//区号
          this.mobile_login_code = response.data.mobile_code_login; //手机验证码登录：0关闭1开启
          this.is_enable = response.data.password_login; //密码登录：0关闭1开启
          this.title.mailInfo_logo = response.data.logo; //商城logo
          this.title.mainHeading = response.data.title1 //主标题
          this.title.subheading = response.data.title2 //副标题
          this.registryEntry = response.data.get_register; //是否显示注册入口
          this.loginToSwitch.mobile_login_code = this.mobile_login_code
          this.loginToSwitch.is_enable = this.is_enable
          this.enable_btn = basic_info?.plugin_setting?.account_login?.enable; //账号登录插件开启状态
          this.need_family = basic_info?.plugin_setting?.account_login?.need_family;
          this.platformAgreement = response.data.platform_agreement //平台协议
          this.registrationProtocol = response.data.register_agreement //注册协议
          this.nameOfTheMall = response.data.shop_name //商城名称
          localStorage.setItem('shop_name',response.data.shop_name)
          this.form.login_checked = response.data.register_agreement?.default_tick == 1 ? true : false; //是否默认勾选
          if(basic_info.plugin_setting?.car_manage?.is_register_bind){
            // 车辆管理注册车牌显示开关
            this.car_manage_is_register_bind = basic_info.plugin_setting?.car_manage?.is_register_bind;
          }
          // #7728 is_year_end_box_login
          // this.is_year_end_box_login = basic_info.plugin_setting.is_year_end_box_login?basic_info.plugin_setting.is_year_end_box_login:false;
          if (this.enable_btn == '1') { //判断是否为账号密码登录
            this.accountAndPasswordLogin = true
          }
          this.email_login = basic_info?.plugin_setting?.email_register?.is_open;
          if (this.enable_btn != '1' && this.is_enable == 1) { //判断是否为手机号密码
            this.phoneAndPassword = true
          }
          if (this.mobile_login_code && this.is_enable || this.enable_btn == '1') { //登陆方式切换按钮是否显示
            this.loginModeSwitchButton = true
          }
          if (this.mobile_login_code && this.is_enable || this.enable_btn == '1') { //如果两种登陆都开启了并且手机验证码登陆也开启了就默认显示手机验证码登陆并且显示切换按钮
            if(this.mobile_login_code == 1){
              this.phoneAndPassword = false
              this.accountAndPasswordLogin = false
              this.is_enable = false
            }
          }
          if(this.appPlatform){ //如果是app端就只显示手机号密码登录并且取消协议默认勾选
            // this.phoneAndPassword = true
            // this.mobile_login_code = 0
            // this.accountAndPasswordLogin = false
            this.form.login_checked = false
          }
          if (response.data.sms && response.data.sms.captcha.status == "1") {
            this.imgcode = response.data.sms.captcha.img;
          }
          if(this.fun.isWalletApp()&&response.data.is_wallet_log){
            this.isWalletLogin = true;//开启了钱包app登录，只适用于钱包app环境，type为18
            // this.requiredInviter = response.validate_page.invite_page;//是否开启邀请码页面，首次钱包登录需要
          }
        } else {
          Toast(response.msg);
        }
      });
    },
    //发送验证码
    verificationCode() {
      if (this.btnTag) return
      let that = this;
      if (this.fun.isTextEmpty(this.form.country)) {
        Toast("请输入国际区号");
        return;
      }
      if (this.fun.isTextEmpty(this.form.mobile)) {
        Toast(this.$i18n.t('base.enterPhoneNumber'));
        return;
      }

      if (this.form.country == "86" && this.fun.isMoblie(this.form.mobile)) {
        Toast("请填写正确的手机号");
        return;
      }

      if (this.imgcode && this.mobile_login_code == 1 && this.fun.isTextEmpty(this.form.captcha)) {
        Toast("请填写图形验证码");
        return;
      }

      this.toastLogin = Toast({
        duration: -1, // 持续展示 toast
        message: '发送中...'
      });
      //发送获取验证码的请求
      $http
        .get("member.register.alySendCode", {
          mobile: this.form.mobile,
          captcha: this.form.captcha,
          sms_type: 3,
          state: this.form.country,

        })
        .then(
          response => {
            this.toastLogin.clear();
            if (response.result === 1) {
              that.sendCodeAnimation();
            } else {
              //刷新图形验证码
              Toast(response.msg);
              this.form.captcha = "";
              this.getimgdata();
            }
          },
          response => {
            console.log(response.msg);
          }
        );
    },
    //发送验证码 倒计时
    sendCodeAnimation() {
      const TIME_COUNT = 60;
      if (!this.timer) {
        this.count = TIME_COUNT;
        Toast.success(this.$i18n.t('base.verificationCodeSent') );
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--;
            this.btnText = this.$i18n.t('base.resendIn', this.count, { count: this.count });//n秒后重新获取;
            this.btnTag = true;
          } else {
            this.btnTag = false;
            this.btnText = this.$i18n.t('base.getSmsCode');
            clearInterval(this.timer);
            this.timer = null;
          }
        }, 1000);
      }
    },
    //先验证是否导致会员id变更
    getPrepBind() {
      if (!this.mobileForm.mobile) {
        Toast(this.$i18n.t('base.enterPhoneNumber'));
        return;
      }
      if (this.imgcode && !this.mobileForm.captcha) {
        Toast('图形验证码不能为空');
        return;
      }

      if (!this.mobileForm.code) {
        Toast(this.$i18n.t('base.enterVerificationCode') );
        return;
      }

      $http.post('member.member.prepBind', this.mobileForm, '绑定中...').then(
        response => {
          if (response.result == 1) {
            if (response.data.is_show) {
              // 显示 导致会员id变更 弹窗
              this.showChangeID = true;
              this.changidInfo.uid = response.data.uid;
              this.changidInfo.change_uid = response.data.change_uid;
            } else {
              //不显示提示弹窗
              this.register_V2();
            }
          } else {
            Toast(response.msg);
          }
        },
        response => {
          Toast(response.msg);
        }
      );
    },
    isAppLogin() {
      $http
        .post("member.login.phoneSetGet", {})
        .then(response => {
          // console.log(response);
          if (response.result == 1) {
            // if(response.data.phone_oauth == '1'){
            // 	this.appShow=true;
            // }else if(response.data.phone_oauth == '0' ){
            // 	this.appShow=false;
            // }else{
            // 	return;
            // }
            this.appShow = parseInt(response.data.phone_oauth);
          } else {
            return;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    verificationCode_V2() {
      if (this.fun.isTextEmpty(this.mobileForm.mobile)) {
        Toast(this.$i18n.t('base.enterPhoneNumber'));
        return;
      }

      if (this.fun.isMoblie(this.mobileForm.mobile)) {
        Toast("请填写正确的手机号");
        return;
      }

      if (this.fun.isTextEmpty(this.mobileForm.captcha) && this.imgcode) {
        Toast("请填图形验证码");
      } else {
        Toast.loading({
          duration: 0, // 持续展示 toast
          forbidClick: true,
          message: "发送中"
        });
        // 发送获取验证码的请求
        $http
          .get("member.register.sendCodeV2", {
            mobile: this.mobileForm.mobile,
            state: "86",
            captcha: this.mobileForm.captcha,
          })
          .then(
            response => {
              Toast.clear();
              if (response.result == 1) {
                this.sendCodeAnimation();
              } else {
                Toast(response.msg);
                //刷新图形验证码
                this.mobileForm.captcha = "";
                this.getimgdata();
              }
            },
            response => {
              console.log(response.msg);
            }
          );
      }
    },
    //获取图片验证码
    getimgdata() {
      $http
        .get("home-page.getCaptcha")
        .then(res => {
          if (res.data.captcha) {
            this.imgcode = res.data.captcha.img;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    async register_V2() {
      let json = {
        country: '86',
        mobile: this.mobileForm.mobile,
        captcha: this.mobileForm.captcha,
        code: this.mobileForm.code,
        close: 1
      };

      $http.post('member.member.bindMobile', json, '绑定中...').then(
        async response => {
          Toast(response.msg);
          if (response.result == 1) {
            let isAppCoinK = this.$route.query.CoinK||false;//是否来着第三方app的跳转
            if(isAppCoinK) {
              // 第三方app登录对接，登录成功后请求接口将信息postmassge给APP
              let _Res = await $http.post("plugin.ad-task.frontend.index.login", {});
              if (_Res.result === 1 && _Res.data) {
                console.log('postmassge========',_Res);
                try {
                  uni.postMessage({data: {sourceData: _Res.data}});
                } catch (error) {
                  console.log('postmassge error========',error);
                }
              } else this.$dialog.alert({message: _Res.msg});
              return;
            }

            if (this.changidInfo && this.changidInfo.change_uid) {
              window.localStorage.setItem("uid", this.changidInfo.change_uid);
            }
            this.showChangeID = false;
            if (this.ys_short_url_redirect_url) {
              window.location.href = this.ys_short_url_redirect_url + '&from=mobile';
              return;
            }

            if (this.login_back_url) {
              window.location.href = this.login_back_url;
            } else {
              this.$router.push(this.fun.getUrl("home"));
            }
          }
        },
        response => {
          Toast(response.msg);
        }
      );
    },
    isBase64(path) {
      if (path && (path.indexOf('http') > -1 || path.indexOf('www') > -1)) {
        return false;
      }
      return true;
    },
    toRegisterText() { //跳转到注册页面
      let query = {pageType: 'register'};
      let isAppCoinK = this.$route.query.CoinK || false;//是否来着第三方app的跳转
      if(isAppCoinK) query.CoinK = 1;
      this.$router.push(this.fun.getUrl("register", {}, query));
    },
    getParam(name, url) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      // var r = window.location.search.substr(1).match(reg);
      if (url.indexOf('?') > -1) {
        var r = url.split('?')[1].match(reg);
        if (r != null) return unescape(r[2]);
        return null;
      }
      return null;
    },
    init_appCoinK(){
      let isAppCoinK = this.$route.query.CoinK||false;//是否来着第三方app的跳转
      if(isAppCoinK) {
        // <!-- uni 的 SDK -->
        if (!document.getElementById("uniWebview")) {
          //避免多次引入
          const script = document.createElement("script");
          script.type = "text/javascript";
          script.src = "https://unpkg.com/@dcloudio/uni-webview-js@0.0.3/index.js";
          script.id = "uniWebview";
          document.body.appendChild(script);
          script.onload = script.onreadystatechange = function() {
            if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
              console.log("uniWebview onload=======================");
              document.addEventListener('UniAppJSBridgeReady', function() {
                console.log('===========UniAppJSBridgeReady success=========');
              });
            }
            script.onload = script.onreadystatechange = null; //删除事件处理函数。
          };
        }

      }
    },
    gotoUrl(name, params = {}, query={}) {
      let _params = { ...params };
      let _query = { ...query };
      if(this.$route.query.CoinK) {
        _query.CoinK = 1;
      }
      this.$router.push(this.fun.getUrl(name, _params,_query));
    },
    toLink(url){
      if(!url) return;
      window.location.href = url;
    },
    switchLanguage() {
      this.$i18n.locale = this.$i18n.locale == "en" ? "ru" : "en"; // 切换语言
      window.localStorage.setItem('localeLang', this.$i18n.locale);
      // 刷新页面
      window.location.reload();
    },
  },
  components:{car_number_keyboard_popup,countryCode}
};
